#!/bin/bash
# Authored By Allan Liu
# 增加指定项目的管理员

# 还应当完成资源的自动管理 tomcat内的资源字符
# 以及项目的移除


if [ $UID -ne 0 ]; then
    echo "Superuser privileges are required to run this script."
    echo "e.g. \"sudo $0\""
    exit 1
fi

shift

if [[ ! $1 ]]; then
    echo "-u is required;-u: manager name"
    echo "e.g. ./addprojectmanager.sh -u test -n test -p test"
    exit 1
fi
userName=$1
shift
shift
if [[ ! $1 ]]; then
    echo "-n is required;-n: project name"
    echo "e.g. ./addprojectmanager.sh -u test -n test -p test"
    exit 1
fi
projectName=$1
shift
shift
if [[ ! $1 ]]; then
    password=efs123456
else
    password=$1
fi

echo -n "New account?(y/n)："
read newAccount
if [[ ${newAccount} = 'y' ]]; then
    useradd ${userName}
    echo ${password} |passwd --stdin ${userName}
    chage -d0 ${userName}
    usermod -aG ${projectName} ${userName}
else
    usermod -aG ${projectName} ${userName}
fi



echo "you have successfully added a manager named ${userName} for ${projectName}"